package cn.com.chec.en.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

import org.apache.commons.lang.StringUtils;

public class PropertiesUtil
{
  private static List<Properties> list;
  private static Properties proConstants;
  private static Properties proImage;

  private static void init()
  {
    try
    {
      list = new ArrayList<Properties>();

      proImage = new Properties();
      InputStream inImage = PropertiesUtil.class.getClassLoader()
        .getResourceAsStream("image.properties");
      proImage.load(inImage);
      list.add(proImage);

      proConstants = new Properties();
      InputStream inConstants = PropertiesUtil.class.getClassLoader()
        .getResourceAsStream("constants.properties");
      proConstants.load(inConstants);
      list.add(proConstants);
    }
    catch (IOException e) {
      e.printStackTrace();
    }
  }

  public static String getValue(String key)
  {
    String value = "";
    if (list == null) {
      init();
    }
    for (Properties p : list) {
      if (StringUtils.isBlank(p.getProperty(key))) {
        continue;
      }
      value = p.getProperty(key);
    }
    return value;
  }

  public static void main(String[] args) {
    System.out.println(getValue("DBPASSWORD"));
  }
}